<#import "../template.ftl" as t/>
<@t.html ; part>
    <#if part="head">
        <link href="<@spring.url "/resources/plugins/datatables/dataTables.bootstrap.css"/>" rel="stylesheet">
        <link href="<@spring.url "/resources/plugins/datatables/responsive.dataTables.min.css"/>" rel="stylesheet">
    </#if>
    <#if part="body">
        <div class="panel">
            <div class="panel-body">
                <div class="pad-btm form-inline">
                    <div class="row">
                        <div class="col-sm-6 table-toolbar-left">
                            <button id="demo-btn-addrow" class="btn btn-info" onclick="passConnect()">通过关联</button>
                            <button id="demo-btn-addrow" class="btn btn-danger" onclick="refuseConnect()">驳回关联</button>
                        </div>
                        <div class="col-sm-6 table-toolbar-right">
                        </div>
                    </div>
                </div>
                <table id="dt-basic" class="table table-striped table-bordered"
                       cellspacing="0" width="100%">
                    <thead>
                    <tr>
                        <th class="text-center hidden-xs">序号</th>
                        <th>公司名称</th>
                        <th>绑定状态</th>
                        <th class="hidden-xs">电压等级（kV）</th>
                        <th class="hidden-xs">预估年电量（万kWh）</th>
                        <th class="hidden-xs">户号个数</th>
                        <th class="hidden-xs">用户类型</th>
                        <th class="hidden-xs">客户地区</th>
                        <th>销售</th>
                        <th>关联</th>
                    </tr>
                    </thead>
                    <tbody>
                        <#if companyBakHashMap?? && (companyBakHashMap?keys)??>
                            <#list companyBakHashMap?keys as k>
                                <tr>
                                    <td class="hidden-xs">${k_index+1}</td>
                                    <td>${companyBakHashMap[k].companyName!}</td>
                                    <td><#if companyBakHashMap[k].bangStatus??><#if companyBakHashMap[k].bangStatus ==1>未绑定<#elseif companyBakHashMap[k].bangStatus==2>已绑定<#else>绑定有争议</#if></#if></td>
                                    <td class="hidden-xs">${companyBakHashMap[k].voltageStep!}</td>
                                    <td class="hidden-xs"><#if companyBakHashMap[k].elecConsumption??>${(companyBakHashMap[k].elecConsumption?number)/10000}</#if></td>
                                    <td class="hidden-xs">${companyBakHashMap[k].elecAccountNum!}</td>
                                    <td class="hidden-xs"><#if companyBakHashMap[k].types??><#if companyBakHashMap[k].types==1>零售用户<#else>电力用户</#if></#if></td>
                                    <td class="hidden-xs">${(companyBakHashMap[k].cityParent.name)!}${(companyBakHashMap[k].currentCity.name)!}</td>
                                    <td>
                                        <p><strong>${(companyBakHashMap[k].user.name)!}</strong></p>
                                        <#if applyHashMap?? && applyHashMap[k]??>
                                            <#list applyHashMap[k] as apply>
                                            <p>&nbsp;&nbsp;&nbsp;&nbsp;${(apply.user.name)!}</p>
                                            </#list>
                                        </#if>
                                    </td>
                                    <td>
                                        <#if (companyBakHashMap[k].user)??>
                                            <p><input type="checkbox" name="chooseUser" value="${k}_${companyBakHashMap[k].user.id}"/></p>
                                        </#if>
                                        <#if applyHashMap?? && applyHashMap[k]??>
                                            <#list applyHashMap[k] as apply>
                                                <p><input type="checkbox" name="chooseUser" value="${k}_${apply.user.id}"/></p>
                                            </#list>
                                        </#if>
                                    </td>
                                </tr>
                            </#list>
                        </#if>
                    </tbody>
                </table>
            </div>
        </div>

    </#if>

    <#if part="foot_script">
        <script src="<@spring.url "/resources/plugins/datatables/jquery.dataTables.js"/>"></script>
        <script src="<@spring.url "/resources/plugins/datatables/dataTables.bootstrap.js"/>"></script>
        <script src="<@spring.url "/resources/plugins/datatables/dataTables.responsive.min.js"/>"></script>
        <script src="<@spring.url "/resources/js/tables-datatables.js"/>"></script>
        <script type="text/javascript">
            $('#dt-basic').dataTable( {
                "aLengthMenu": [[10, 25, 50, 100, -1], ["10", "25", "50", "100", "所有"]],
                "fnDrawCallback":function (settings) {
                    //$("#dt-basic thead tr th:first").removeClass("sorting_asc");
                    //$("#dt-basic tbody tr td:first").removeClass("sorting_asc");
                }
            });
            
            function passConnect() {
                if (confirm("确定通过关联吗？")){
                    var companyUsers = new Array();
                    $("input:checkbox[name='chooseUser']:checked").each(function () {
                        companyUsers.push($(this).val());
                    });
                    if (companyUsers.length > 0) {
                        $.post("<@spring.url "/saleManage/apply/pass"/>",{
                            companyUsers:companyUsers}, function (data) {
                            alert(data.message);
                            if (data.code == 1) {
                                window.location.reload();
                            }
                        });
                    } else {
                        alert("请选择要通过关联的记录。");
                    }

                }
                
            }
            
            function refuseConnect() {
                if (confirm("确定驳回关联吗？")){
                    var companyUsers = new Array();
                    $("input:checkbox[name='chooseUser']:checked").each(function () {
                        companyUsers.push($(this).val());
                    });
                    if (companyUsers.length > 0) {
                        $.post("<@spring.url "/saleManage/apply/refuse"/>", {
                            companyUsers: companyUsers
                        }, function (data) {
                            alert(data.message);
                            if (data.code == 1) {
                                window.location.reload();
                            }
                        });
                    } else {
                        alert("请选择要驳回关联的记录。");
                    }
                }
            }



        </script>


    </#if>
</@t.html>